﻿<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <script src="~/js/frame.js"></script>
</head>
<body>
    <div class="container-fluid">
        <form id="form">
            <div class="formrow">
                <div class="col-xs-12">
                    <div class="formtitle required">兼职类别</div>
                    <div class="formcontent">
                        <select class="form-control required" name="JobType" id="JobType">
                            <option value="200" selected="selected">人员兼职</option>
                            <option value="100">部门兼职</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="formrow" id="UserJobContent">
                <div class="col-xs-12">
                    <div class="formtitle required">兼职人员</div>
                    <div class="formcontent">
                        <cloud-tree id="UserJob" url="tree" control-type="selectuser" select-type="single" style="height:50px"></cloud-tree>
                    </div>
                </div>
            </div>
            <div class="formrow" style="display:none" id="OUJobContent">
                <div class="col-xs-12">
                    <div class="formtitle required">兼职部门</div>
                    <div class="formcontent">
                        <cloud-tree id="OUJob" url="tree" control-type="selectou" select-type="single" style="height:50px"></cloud-tree>
                    </div>
                </div>
            </div>
            <div class="formrow">
                <div class="col-xs-12">
                    <div class="formtitle">排序</div>
                    <div class="formcontent">
                        <input name="SortNum" type="text" class="form-control" placeholder="" value="0">
                    </div>
                </div>
            </div>
            <div class="formbtnop">
                <button class="btn btn-primary cloudbtn" type="button" onclick="Save()"><span class="btntext">保 存</span></button>
                <button class="btn cloudbtn" type="button" onclick="Close()"><span class="btntext">关 闭</span></button>
            </div>
        </form>
    </div>
    <script>
        var validator = $("#form").validate();
        $(function () {
            RenderTree();
            $("#JobType").change(function () {
                var JobType = $('#JobType option:selected').val();
                if (JobType == "200") {
                    $("#UserJobContent").show();
                    $("#OUJobContent").hide();
                } else {
                    $("#UserJobContent").hide();
                    $("#OUJobContent").show();
                }
                RenderTree();
            })
        })
        function Save() {
            if (validator.form()) {
                var param = $("#form").GetForm();
                param.UserGuid = GetUrlParam("userguid");
                if (param.JobType == "200") {
                    var UserJobGuid = GetTreeSelectValue("UserJob");
                    if (!UserJobGuid) {
                        OpenWaring("未选择兼职对象！");
                        return;
                    } else {
                        param.UserJobGuid = UserJobGuid;
                    }
                } else {
                    var UserJobGuid = GetTreeSelectValue("OUJob");
                    if (!UserJobGuid) {
                        OpenWaring("未选择兼职对象！");
                        return;
                    } else {
                        param.UserJobGuid = UserJobGuid;
                    }
                }
                CloudPost(param, "opinsert", function (res) {
                    if (res.code == 0) {
                        OpenSuccess("保存成功！", function () {
                            CloseDialog();
                        })
                    } else {
                        OpenFail(res.data)
                    }
                })
            }
        }
        function Close() {
            CloseDialog();
        }
    </script>
</body>
</html>
